// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// This file shows how you can specify extensions to generics with type
/// bounds. For example, you can define an extension method for `List<int.dart>`,
/// and it won't apply to `List<String>`.
void main() {
  print([1, 2, 3].sum);
  print(DateTime.now().localFormat());
  print(DateTime.now().localFormat().replaceAll(':', '-').replaceAll(' ', '-'));
  print(DateTime.now().localFormat().replaceAll(r"", '-'));
}

extension on List<int> {
  int get sum => fold(0, (a, b) => a + b);
}

extension on DateTime{
  String localFormat(){
    //2021-04-26 12:12:12
    //"$y-$m-$d $h:$min:$sec.$ms$us";
    return this.toString().substring(0,19);
  }
}